<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
	<ui:define name="title">
		SGMF :: Fornecedor
	</ui:define>

	<ui:define name="content">
		<p:panel>
			<h:form id="fornecedorForm">
				<h:inputHidden id="fornecedorId" value="#{fornecedorBean.fornecedor.id}" rendered="#{fornecedorBean.fornecedor.id != null}" />
				<h:inputHidden id="enderecoId" value="#{fornecedorBean.endereco.id}" rendered="#{fornecedorBean.endereco.id != null}" />
				<p:fieldset legend="Fornecedor">
					<p:panelGrid columns="3" styleClass="borderless">
						<p:outputLabel value="CNPJ" for="cnpj" />
						<p:inputMask id="cnpj" label="CNPJ" value="#{fornecedorBean.fornecedor.cnpj}" required="true" mask="99.999.999/9999-99" size="50">
							<f:validator binding="#{cnpjValidator}" />
						</p:inputMask>
						<p:message for="cnpj" />
						<p:outputLabel value="Razão Social" for="razao_social" />
						<p:inputText id="razao_social" label="Razão Social" value="#{fornecedorBean.fornecedor.razaoSocial}" required="true" maxlength="50" size="50" />
						<p:message for="razao_social" />
						<p:outputLabel value="Nome Fantasia" for="nome_fantasia" />
						<p:inputText id="nome_fantasia" label="Nome Fantasia" value="#{fornecedorBean.fornecedor.nomeFantasia}" required="true" maxlength="50" size="50" />
						<p:message for="nome_fantasia" />
					</p:panelGrid>
				</p:fieldset>
				<br />
				<p:fieldset legend="Endereço">
					<p:panelGrid columns="3" styleClass="borderless">
						<p:outputLabel value="CEP" for="cep" />
						<p:inputMask id="cep" label="CEP" value="#{fornecedorBean.endereco.cep}" required="true" mask="99.999-999" size="50" />
						<p:message for="cep" />
						<p:outputLabel value="Estado" for="estado" />
						<p:selectOneMenu id="estado" value="#{fornecedorBean.endereco.estado}" required="true">
							<f:selectItems value="#{fornecedorBean.estados}" var="estado" itemValue="#{estado}" itemLabel="#{estado}" />
						</p:selectOneMenu>
						<p:message for="estado" />
						<p:outputLabel value="Cidade" for="cidade" />
						<p:inputText id="cidade" label="Cidade" value="#{fornecedorBean.endereco.cidade}" required="true" maxlength="50" size="50" />
						<p:message for="cidade" />
						<p:outputLabel value="Bairro" for="bairro" />
						<p:inputText id="bairro" label="Bairro" value="#{fornecedorBean.endereco.bairro}" required="true" maxlength="50" size="50" />
						<p:message for="bairro" />
						<p:outputLabel value="Logradouro" for="logradouro" />
						<p:inputText id="logradouro" label="Logradouro" value="#{fornecedorBean.endereco.logradouro}" required="true" maxlength="50" size="50" />
						<p:message for="logradouro" />
						<p:outputLabel value="Número" for="numero" />
						<p:inputText id="numero" label="Número" value="#{fornecedorBean.endereco.numero}" required="true" maxlength="5" size="50">
							<f:convertNumber type="number" />
						</p:inputText>
						<p:message for="numero" />
						<p:outputLabel value="Complemento" for="complemento" />
						<p:inputText id="complemento" label="Complemento" value="#{fornecedorBean.endereco.complemento}" maxlength="50" size="50" />
						<h:outputText />
					</p:panelGrid>
				</p:fieldset>
				<br />
				<p:commandButton id="salvar" value="Salvar"	action="#{fornecedorBean.salvar}" update=":growl, :fornecedorForm, :datatableForm" icon="ui-icon-disk" />
				<p:commandButton id="novo" value="Novo"	actionListener="#{fornecedorBean.novo}" process="@this" update=":fornecedorForm" icon="ui-icon-document" />
			</h:form>
			<br />
			<h:form id="datatableForm">
				<p:dataTable id="datatable" var="fornecedor"
					value="#{fornecedorBean.fornecedores}" rows="10" paginator="true"
					paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					currentPageReportTemplate="({currentPage} de {totalPages})" rowsPerPageTemplate="10, 15, 20" emptyMessage="Nenhum registro encontrado.">
					<p:column headerText="CNPJ">
						<h:outputText value="#{fornecedor.cnpj}" />
					</p:column>
					<p:column headerText="Razão Social">
						<h:outputText value="#{fornecedor.razaoSocial}" />
					</p:column>
					<p:column headerText="Nome Fantasia">
						<h:outputText value="#{fornecedor.nomeFantasia}" />
					</p:column>
					<p:column style="width: 32px;">
						<p:commandButton icon="ui-icon-pencil" title="Editar" actionListener="#{fornecedorBean.editar(fornecedor)}" update=":fornecedorForm" />
					</p:column>
					<p:column style="width: 32px;">
						<p:commandButton icon="ui-icon-trash" title="Excluir" actionListener="#{fornecedorBean.excluir(fornecedor)}" update=":growl, :fornecedorForm :datatableForm" >
							<p:confirm header="Confirmação" message="Deseja realmente excluir este fornecedor?" icon="ui-icon-alert" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</h:form>
		</p:panel>
	</ui:define>
</ui:composition>

</html>